package main

import (
	"GinShop/config"
	"GinShop/controller"
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
	"strings"
)

var appEnv map[string]string

/**
确定开发环境，需要修改在配置文件中修改即可
*/
func init() {
	appEnv = make(map[string]string)
	appEnv["debug"] = gin.DebugMode
	appEnv["test"] = gin.TestMode
	appEnv["release"] = gin.ReleaseMode
}

func main() {
	//初始化配置文件
	config.InitConfig()

	env := config.Config.Section("env")
	port, err := env.GetKey("Port")
	if err != nil {
		panic(err.Error())
	}
	mode, err := env.GetKey("Mode")
	if err != nil {
		panic(err.Error())
	}

	gin.SetMode(appEnv[strings.ToLower(fmt.Sprintf("%s", mode))])

	//获取app，启动服务
	app := config.Init()

	//启动路由
	controller.Api(app)
	controller.Home(app)

	log.Fatal(app.Run(fmt.Sprintf(":%s", port)))
}
